package com.hry.store.cms.service.impl;

import com.hry.store.cms.dao.TopCategoryMapper;
import com.hry.store.cms.pojo.TopCategory;
import com.hry.store.cms.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private TopCategoryMapper topCategoryMapper;

    /**
     * 查询所有一级分类集合
     * @return
     */
    @Override
    public List<TopCategory> getTopCategory() {
        return topCategoryMapper.selectAllTopCategory();
    }

    /**
     * 通过一级标题查询标题内容
     * @param topCategoryId
     * @return
     */
    @Override
    public TopCategory getByTopCategory(Integer topCategoryId) {
        return topCategoryMapper.selectByPrimaryKey(topCategoryId);
    }

    /**
     * 更新一级标题
     * @param topCategoryId
     * @param topCategoryName
     * @param status
     * @return
     */
    @Override
    public int updateTopCategoryId(Integer topCategoryId, String topCategoryName, Integer status) {
        TopCategory topCategory = new TopCategory();
        topCategory.setTopCategoryId(topCategoryId);
        topCategory.setStatus(status);
        topCategory.setTopCategoryName(topCategoryName);
        return topCategoryMapper.updateByPrimaryKeySelective(topCategory);
    }

    /**
     * 删除一级标题
     * @param topCategoryId
     * @return
     */
    @Override
    public int deleteByTopCategory(Integer topCategoryId) {
        return topCategoryMapper.deleteByPrimaryKey(topCategoryId);
    }

    /**
     * 添加一级标题
     * @param topCategoryName
     * @param status
     * @return
     */
    @Override
    public int addTopCategory(String topCategoryName, Integer status) {
        TopCategory topCategory = new TopCategory();
        topCategory.setTopCategoryName(topCategoryName);
        topCategory.setStatus(status);
        return topCategoryMapper.insertSelective(topCategory);
    }
}
